
"""Add a custom command to mitmproxy's command prompt."""

from mitmproxy import command
from mitmproxy import ctx

import requests

import logging



class CommandCrawl:
    def __init__(self):
        self.num = 0
        self.urls_to_visit = [
            "https://fund.10jqka.com.cn/datacenter/jz/",
        ]
        self.current_index = 0



    @command.command("crawler.start")
    def inc(self) -> None:
        self.num += 1
        logging.info(f"CommandCrawl num = {self.num}")
        if self.current_index < len(self.urls_to_visit):
            url = self.urls_to_visit[self.current_index]
            logging.info(f"\n******\n*******\nVisiting URL: {url}\n *****Here will stuck mitmproxy, not work!!!")
            # requests.get(url) #Here will stuck mitmproxy, not work!!!
            # Process the response as needed
            self.current_index += 1
        else:
            logging.info("\n******\n*******\nAll URLs visited")

addons = [CommandCrawl()]